package com.betty.cscams.controller;

import java.util.List;

import com.betty.cscams.common.http.HttpResult;
import com.betty.cscams.constant.SysConstants;
import com.betty.cscams.entity.*;
import com.betty.cscams.service.SysDeptService;
import com.betty.cscams.service.SysUserDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * 机构控制器
 */
@RestController
@RequestMapping("dept")
public class SysDeptController {

	@Autowired
	private SysDeptService sysDeptService;
	@Autowired
	private SysUserDeptService sysUserDeptService;
	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysDept record) {
		return HttpResult.ok(sysDeptService.save(record));
	}

	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysDept> records) {
		return HttpResult.ok(sysDeptService.delete(records));
	}

	@GetMapping(value="/findTree")
	public HttpResult findTree() {
		return HttpResult.ok(sysDeptService.findTree());
	}

	@GetMapping(value="/findStudentTree")
	public HttpResult findStudentTree() {
		return HttpResult.ok(sysDeptService.findStudentTree());
	}

	@GetMapping(value="/findDeptsByUser")
	public HttpResult findDeptsByUser(Long userId) {
		return HttpResult.ok(sysUserDeptService.findDeptsByUser(userId));
	}


}
